home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Random2.0 / RandomHist / Random.h < prev    next >
Text File  |  1995-06-12  |  3KB  |  92 lines

  1. //
  2. // Random
  3. //
  4. // An Objective-C class for NeXT computers to provide services for random
  5. // number generation.
  6. //
  7. // History:
  8. //   pre 1990 Mar 23
  9. //     Used random number generation algorithm from K&R.
  10. //   1990 Mar 23
  11. //     Modified to use algorithm with cycle length of 8.8 trillion.
  12. //   1990 Mar 26
  13. //     * Added archiving.
  14. //     * Added randMax:, randMin:Max:, and percent:.
  15. //   1991 Apr 26
  16. //     * Changed to use +alloc and -init as all NeXTStep 2.0 objects should.
  17. //   1991 May 30
  18. //     * Prepared for distribution and initial release.
  19. //   1991 Nov 05
  20. //     * Added - (BOOL)bool method.
  21. //   1991 Dec 30
  22. //     * Changed - (float)percent to return double instead.
  23. //     * Added - (double)randFunc: method.
  24. //   1992 Feb 27
  25. //     * Added Gaussian functionality.
  26. //   1992 Apr 02
  27. //     * New version, 2.0.
  28. //     * New Architecture: Split generation/interpretation.
  29. //
  30. // Version 2.0, 1992 Apr 02 
  31. //
  32. // Written by Gregor Purdy
  33. // gregor@umich.edu
  34. //
  35. // See the README file included for information
  36. // and distribution and usage rights. 
  37. //
  38. // Copyright (C) 1992 Contemporary Design Studios. All rights reserved.
  39. //
  40.  
  41.  
  42. #import <objc/Object.h>
  43. #import <objc/typedstream.h>
  44. #import "RandomEngine.h"
  45.  
  46.  
  47. #define RAND_RANGE    ((ulong)0xffffffff)
  48.  
  49.  
  50. typedef double (*ddfunc)(double);            // Double Function Returning Double.
  51.  
  52.  
  53. @interface Random : Object
  54.  
  55.  
  56. {
  57.     id        engineClass;        // Class for generation.
  58.     ulong    unit;            // Unit of generation for generation class.
  59.     ulong    bufsize;        // unit / 8.
  60.     uchar    *bitbuffer;        // Buffer of random bits.
  61.     uchar    *bytebuffer;        // Buffer of random bits.
  62.     ulong    curbit;            // Current location in the buffer.
  63.     ulong    curbyte;        // Current location in the buffer.
  64.     id        engine;            // The actual engine.
  65. }
  66.  
  67.  
  68. + (int)version;                // Version of the class.
  69.  
  70. - initEngineClass:aClass;        // Use the class given for generation.
  71. - initEngineInstance:anObject;        // Use the instance given for generation.
  72.                     //   THIS IS THE DESIGNATED INITIALIZER.
  73.  
  74. - (ulong)rand;                // Return a random integer.
  75. - (ulong)randMax:(ulong)max;        // Return a random integer 0 <= x <= max.
  76. - (ulong)randMin:(ulong)min        // Return a random integer min <= x <= max.
  77.     max:(ulong)max;
  78. - (double)percent;            // Return a random double 0.0 <= x <= 1.0.
  79. - (BOOL)bool;                // Return randomly, YES or NO.
  80.  
  81. - (double)randFunc:(ddfunc)func;    // See description file.
  82.  
  83. - read:(NXTypedStream *)stream;        // De-archive from a typed stream.
  84. - write:(NXTypedStream *)stream;    // Archive to a typed stream.
  85.  
  86.  
  87. @end
  88.  
  89.  
  90. //
  91. // End of file.
  92. //